# -*- coding = utf-8 -*-
# @Time : 2023/3/11 3:27
# @Author : 龙王赘婿_彪少
# @File : strformat.py
# @Software: PyCharm

# 功能：

class strformat:
    name = "liuzhibiao"
    age = 28
    print(f"姓名：{name}年龄{age}")
    print(r"姓名：{name}年龄{age}")  #r"这是显示原始字符串"


    '''
    %c	 格式化字符及其ASCII码
    %s	 格式化字符串
    %d	 格式化整数
    %u	 格式化无符号整型
    %o	 格式化无符号八进制数
    %x	 格式化无符号十六进制数
    %X	 格式化无符号十六进制数（大写）
    %f	 格式化浮点数字，可指定小数点后的精度
    %e	 用科学计数法格式化浮点数
    %E	 作用同%e，用科学计数法格式化浮点数
    %g	 %f和%e的简写
    %G	 %f 和 %E 的简写
    %p	 用十六进制数格式化变量的地址
    '''

    '''
    *	    定义宽度或者小数点精度
    -	    用做左对齐
    +	    在正数前面显示加号( + )
    <sp>	在正数前面显示空格
    #	    在八进制数前面显示零('0')，在十六进制前面显示'0x'或者'0X'(取决于用的是'x'还是'X')
    0	    显示的数字前面填充'0'而不是默认的空格
    %	    '%%'输出一个单一的'%'
    (var)	映射变量(字典参数)
    m.n.	m 是显示的最小总宽度,n 是小数点后的位数(如果可用的话)
    '''
    def doc(self):
        print("https://blog.csdn.net/ex_6450/article/details/125031543")

    def __init__(self):
        # self.demo1()
        # self.demo2()
        # self.demo3()
        # self.demo4()
        self.demo5()

    def demo1(self):
        # str = "abcdefghijklmnopqrstuvwxyz"
        # str = "1234567890"
        # str = 123456789
        str = 0x12
        print("str = ", str, " type = ", type(str))

        form1 = '%s' % str
        print("form1 = ", form1, " type = ", type(form1))

        form2 = '%.4o' % str
        print("form2 = ", form2, " type = ", type(form2))

    def demo2(self):
        num = (1, 14, -44, 100, 314, 11)
        form = "%.4d:%.4d:%.4d:%.4d:%.4d:%.4d" % num
        print("form = ", form, "     type = ", type(form))
        form = "%.4o:%.4o:%.4o:%.4o:%.4o:%.4o" % num
        print("form = ", form, "     type = ", type(form))
        form = "%4o:%4o:%4o:%4o:%4o:%4o" % num
        print("form = ", form, "     type = ", type(form))
        form = "%.4x:%.4x:%.4x:%.4x:%.4x:%.4x" % num
        print("form = ", form, "     type = ", type(form))
        form = "%.4X:%.4X:%.4X:%.4X:%.4X:%.4X" % num
        print("form = ", form, "     type = ", type(form))
        form = "%.2u:%.2u:%.2u:%.2u:%.2u:%.2u" % num
        print("form = ", form, "     type = ", type(form))

    def demo3(self):
        num = ('a', 'b', 'c', 'd', 'e', 'f')
        form = "%c:%c:%c:%c:%c:%c" % num
        print("form = ", form, "     type = ", type(form))
        form = "%2c:%2c:%2c:%2c:%2c:%2c" % num
        print("form = ", form, "     type = ", type(form))
        form = "%.2c:%.2c:%.2c:%.2c:%.2c:%.2c" % num
        print("form = ", form, "     type = ", type(form))

    def demo4(self):
        num = 13143.1415926
        form = "%f" % num
        print("form = ", form, "     type = ", type(form))
        form = "%2f" % num
        print("form = ", form, "     type = ", type(form))
        form = "%.2f" % num
        print("form = ", form, "     type = ", type(form))
        form = "%1.2f" % num
        print("form = ", form, "     type = ", type(form))
        form = "%f" % num
        print("form = ", form, "     type = ", type(form))

    def demo5(self):
        num = 12
        form = "%d" % num
        print("form = ", form, "     type = ", type(form))
        form = "%4d" % num
        print("form = ", form, "     type = ", type(form))
        form = "%.4d" % num
        print("form = ", form, "     type = ", type(form))

        form = "%o" % num
        print("form = ", form, "     type = ", type(form))
        form = "%#o" % num
        print("form = ", form, "     type = ", type(form))
        form = "%#8o" % num                                         # 懂了懂了，8代表显示八位，.8代表8个数字
        print("form = ", form, "     type = ", type(form))          #     0o14
        form = "%#.8o" % num
        print("form = ", form, "     type = ", type(form))          # 0o00000014

        form = "%x" % num
        print("form = ", form, "     type = ", type(form))
        form = "%#x" % num
        print("form = ", form, "     type = ", type(form))
        form = "%.5x" % num
        print("form = ", form, "     type = ", type(form))
        form = "%#.5x" % num
        print("form = ", form, "     type = ", type(form))

        form = bin(num)                                             # 二进制
        print("form = ", form, "     type = ", type(form))


if __name__ == "__main__":
    s = strformat()
    print("shuzi{:d}".format(12))
